﻿using AutoMapper; //AutoMapper
using PcProject.Application.Service.AutoMapper;
using PcProject.Domain.IRepository;
using PcProject.Domain.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PcProject.Application.Service.Products
{
    /// <summary>
    /// 商品模块
    /// </summary>
    public class ProCateService:IProCateService
    {
        /// <summary>
        /// 构造函数依赖注入
        /// </summary>
        private IProCateRepository _proCateRepository;
        private IMapper _mapper;
        /// <summary>
        /// 函数依赖注入
        /// </summary>
        /// <param name="productRepository"></param>
        /// <param name="mapper"></param>
        public ProCateService(IProCateRepository proCateRepository, IMapper mapper)
        {
            _proCateRepository = proCateRepository;
            _mapper = mapper;
        }


        /// <summary>
        /// 显示+分页+查询
        /// </summary>
        /// <param name="pname">查询参数</param>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">条数</param>
        /// <param name="totalCount">总条数</param>
        /// <returns></returns>
        public List<ProductCategory> GetProCatesAsync(/*int pageIndex, int pageSize, out int totalCount*/)
        {
            return _proCateRepository.GetProCatesAsync(/*pageIndex, pageSize, out totalCount*/);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="obj">表单参数</param>
        /// <returns></returns>
        public async Task<int> InsertAsync(ProductCategoryDto obj)
        {
            ProductCategory a = _mapper.Map<ProductCategory>(obj);
            return await _proCateRepository.InserAsync(a);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public async Task<int> DeleAsync(int id)
        {
            return await _proCateRepository.DeleAsync(id);
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public async Task<ProductCategory> FillAsync(int id)
        {
            return await _proCateRepository.FillAsync(id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="obj">表单参数</param>
        /// <returns></returns>
        public async Task<int> UptAsync(ProductCategoryDto obj)
        {
            ProductCategory a = _mapper.Map<ProductCategory>(obj);
            return await _proCateRepository.UptAsync(a);
        }

    }
}
